import jsonschema

# 定义待校验数据
resp = {"name": "张三",
        "age": 23,
        "hobby": ["吃饭", "再吃饭", "还是吃饭"],
        "sex": None,
        "is_delete": True,
        "height": 1.72
        }
# 定义规则 -- 预期结果
schema = {
    "type":"object",
    "requird": ["name","age","hobby","sex","is_delete","height"],
    "properties":{
        "name":{"pattern":"^张"},
        "age": {"const": 23},
        "hobby": {"const": ["吃饭", "再吃饭", "还是吃饭"]},
        "sex": {"const": None},
        "is_delete":{"const":True},
        "height":{"const":1.72}
    }
}

# 效验规则，校验实际结果与预期规则是否相符
res = jsonschema.validate(instance=resp, schema=schema)
print(res)
